<!--
 * @Date: 2023-05-17 13:58:56
 * @LastEditors: wkl
 * @LastEditTime: 2023-05-17 15:38:42
 * @FilePath: /demo/lease.html
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcss.com/qs/6.7.0/qs.min.js"></script>
    <script src="https://cdn.bootcss.com/axios/0.18.0/axios.min.js"></script>
    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/js-base64@3.6.0/base64.min.js"></script>
</head>



<body>

    <iframe id="smart-sailing-iframe" style="width: 100vw;height: 100vh;" frameborder="0"></iframe>
    <script>
        window.addEventListener('message', (e) => {
            if (e.data.key === 'lease-smartailingStock') {
                console.log(e.data.height)
                document.getElementById('smart-sailing-iframe').style.height = e.data.height + 'px'
            }
        }, false)

        // 配置 post 的请求头
        axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'

        const login = () => {
            //用户名
            let userName = 'liutao'
            // 密码
            let password = 'UUr09113!!@@.!'

            let uuid = 'XcvsdfsXZ4e534t346uhj'

            let code = '439x'

            password = password.split('')
            // 数组下标5 添加元素'a'
            password.splice(5, 0, 'a')
            // 数组逆序
            password.reverse()
            // Base64encode
            password = Base64.encode(password)
            // 下标5+ 'tc'字符
            password = password.slice(0, 5) + 'tc' + password.slice(5)
            password = encodeURIComponent(password)

            let url = `https://iflorensextuat.florens.com/auth/password?username=${userName}&password=${password}&uuid=${uuid}&code=${code}`
            let arg = {
                username: userName,
                password: password,
                uuid: uuid,
                code: code
            }

            axios.post(url, Qs.stringify(arg)).then(function (res) {
                if (res.status === 200) {
                    const { data } = res.data
                    let token = data.access_token
                    let src = `https://iflorensextuat.florens.com/lease/smart-sailing-stock?smartSailingToken=${token}`;
                    document.getElementById('smart-sailing-iframe').src = src
                }
            })
        }

        login()
    </script>
</body>

</html>